<?php

namespace App\Admin\Controllers\Wechat;

use App\Models\wechat\CmcWechatReply;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WechatReplyController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {

        return Grid::make(new CmcWechatReply(), function (Grid $grid) {
            $typeIds = ['1'=>'文字消息','2'=>'图片消息','3'=>'图文消息','4'=>'声音消息'];
            $grid->column('id','主键编号')->sortable();
            $grid->column('key','关键字');
            $grid->column('type','消息类型')->using($typeIds);
            $grid->column('data','回复内容');
            $grid->column('status','规则状态')->switch();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CmcWechatReply(), function (Show $show) {
            $status = ['1'=>'启用','0'=>'禁用'];
            $type = ['1'=>'微信模板消息' ,'2'=>'订阅消息'];
            $show->field('id');
            $show->field('key');
            $show->field('type')->using($type);
            $show->field('data');
            $show->field('status')->using($status);
            $show->field('hide');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CmcWechatReply(), function (Form $form) {
            $form->display('id','主键ID');
            $form->text('key','关键字');
            $form->radio('status','规则状态')->options(['1' => '启用', '0'=> '禁用'])->default('1');
            $form->select('type','类型')->options(['1'=>'文字消息','2'=>'图片消息','3'=>'图文消息','4'=>'声音消息',]);
            $form->textarea('data','规则内容')->rows(10);
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
